/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelCompetition.java
 *
 * Created on 19-may-2010, 18:16:29
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;

import edu.ieslaferreria.creditsintesis.logicgame.Parameter;
import edu.ieslaferreria.creditsintesis.rmi.Client;
import edu.ieslaferreria.creditsintesis.rmi.EventChangePanel;
import edu.ieslaferreria.creditsintesis.rmi.EventIniciarInteraccion;
import edu.ieslaferreria.creditsintesis.rmi.EventPanelsInteractionTwoPlayersListener;
import edu.ieslaferreria.creditsintesis.rmi.GameEventInteracctionTwoPanels;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author Administrador
 */
public class JPanelCompetition extends JPanelGame{
 private HashMap<String,String> Options = new HashMap();
    private ArrayList<Parameter> parameters = new ArrayList();
  
 EventIniciarInteraccion listenerComp1;
 EventPanelsInteractionTwoPlayersListener listenerComunicationOtherPanel;
     /** Creates new form JPanelCompetition */


public JPanelCompetition(Client client) {
        initComponents();
        setClient(client);
}
            /*evento para iniciarse tras goin, lanzado por main*/
//listenerComp1 = new EventIniciarInteraccion(null,client.getKindPanel(), true,, pontPanel) {
//
//
//            public void action(RmiEvent event) throws RemoteException {
//
//                EventGoInInteracction ev = (EventGoInInteracction) event;
//r
//                pontPanel = (PontImpl) ev.getPontPartidaInt();
//             setVisible(true);
//            }
//
//   };
//

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxMiniGames = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxTreasures = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jButtonStart = new javax.swing.JButton();
        jButtonVolver = new javax.swing.JButton();

        jComboBoxMiniGames.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBoxMiniGames.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMiniGamesActionPerformed(evt);
            }
        });

        jLabel1.setText("Elige una prueba");

        jComboBoxTreasures.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel2.setText("Elige un Botin");

        jButtonStart.setText("Empezar");
        jButtonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartActionPerformed(evt);
            }
        });

        jButtonVolver.setText("Volver");
        jButtonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVolverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jComboBoxTreasures, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBoxMiniGames, javax.swing.GroupLayout.Alignment.LEADING, 0, 148, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 178, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButtonVolver, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonStart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(91, 91, 91))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxMiniGames, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxTreasures, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addContainerGap(57, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonStart)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonVolver)
                        .addGap(34, 34, 34))))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
    HashMap<String,List<String>>opcions = new HashMap();
         opcions.put(OPCIO_BASICA,toList(new String []{jComboBoxMiniGames.getSelectedItem().toString()}));
      
          try {
            this.getPontPanel().send(new GameEventInteracctionTwoPanels(A_COMPETICIORES,toList(new String[]{getClient().getNom()}),opcions,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }



    }//GEN-LAST:event_jButtonStartActionPerformed

    private void jComboBoxMiniGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMiniGamesActionPerformed

    }//GEN-LAST:event_jComboBoxMiniGamesActionPerformed

    private void jButtonVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVolverActionPerformed

try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio el canvio a mi mismo con boolean de respuesta a false*/
            getClient().onMessage(new EventChangePanel(null,A_PANELINICI,false,alias,getPontPanel()));
            
   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELMENUWAIT,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }

    
    }//GEN-LAST:event_jButtonVolverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonStart;
    private javax.swing.JButton jButtonVolver;
    private javax.swing.JComboBox jComboBoxMiniGames;
    private javax.swing.JComboBox jComboBoxTreasures;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables


 
    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {

     if(opcions.get(OPCIO_BASICA)!=null)   {
      this.jComboBoxTreasures.setModel(new DefaultComboBoxModel(opcions.get(OPCIO_BASICA).toArray()));
      this.jComboBoxMiniGames.setModel(new DefaultComboBoxModel(extras.toArray()));
     }else if(opcions.get(RESPOSTA_PROPOSICIO)!= null){

         if(opcions.get(RESPOSTA_PROPOSICIO).toString().contains(OK)){


try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio a panel wait....en realidad seria iniciar el juego*/
            getClient().onMessage(new EventChangePanel(null,A_PANELWAIT,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_PANELWAIT,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        
        }
         }else if(opcions.get(RESPOSTA_PROPOSICIO).toString().contains(NO)){



try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio a panel wait....en realidad seria iniciar el juego*/
            getClient().onMessage(new EventChangePanel(null,A_COMPETICIO,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_COMPETICIORES,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }
         }else{

             try {
/*meto cliente en un arraylist...los eventos tienen arraylist, quizas seria bastante un string*/
            ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());


             /*envio a panel wait....en realidad seria iniciar el juego*/
            getClient().onMessage(new EventChangePanel(null,A_FUGIDA,false,alias,getPontPanel()));

   /*envio por el puente de la partida a todos los players de susodicha menos yo,
   * enviando mi nombre para que sepan a quien NO debe enviarselo*/
            this.getPontPanel().send(new EventChangePanel(null,A_FUGIDARES,false,alias,getPontPanel()));
        } catch (RemoteException ex) {
            Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }
         }

       }
    }

   
}

